<?php 
require_once "header_editor.php"; 
require_once "db.php"; 
require_once "forms.php"; 
require_once "util.php";
require_once "constants.php";

get_database_connection();

// If it is not on the passed var, it will be on the cookie setted.
if (array_key_exists("object_id", $_GET)) {
  $object_id = $_GET["object_id"];
} else {
  $object_id = $_SESSION["object_id"];
}

// Getting the data from the database and putting into a cookie
$sql = "SELECT * FROM objects WHERE id = $object_id";
$query = mysql_query($sql);
$data = mysql_fetch_assoc($query);

// We set a cookie representing the object_id that we are working right now.
$_SESSION["object_id"] = $object_id;
$_SESSION["object_title"] = $data["title"];

$_SESSION["base_url"] = "/tmp/" . $object_id . "/";
$_SESSION["base_dir"] = dirname(__FILE__) . "/tmp/" . $object_id . "/";

?>



<div class="box_header c6"> 
  <div class="g6"> Paginas do objeto: "<?php echo $_SESSION["object_title"]; ?>" </div>
  <div class="g5" style="text-align: right;"> 
  <a href="add_slide.php" class="green_button"> Adicionar nova pagina </a>
  &nbsp; 
  <a href="preview.php?object_id=<?php echo $_SESSION["object_id"]; ?>" class="green_button">
    Pre-visualizar 
  </a> 
  &nbsp; 
  <a href="generate.php?object_id=<?php echo $_SESSION["object_id"]; ?>" class="green_button">
    Gerar!
  </a>
  </div>
</div>

<div class="c6"> <br/> </div>

<div class="c1 thead"> Posicao </div>
<div class="c3 thead"> Titulo </div>
<div class="c2 thead"> Opcoes </div>

<?php
$sql = "SELECT * FROM slides WHERE object_id = $object_id ORDER BY position ASC";
$res = mysql_query($sql);
while ($f = mysql_fetch_assoc($res)) {
?>

<div class="c1 td"> <?php echo $f['position'] ?></div>
<div class="c3 td"> <?php echo $f['title'] ?></div>
<div class="c2 td"> 
  <a href="edit_slide.php?id=<?php echo $f['id']; ?>" id="editar" tip="Editar a pagina">
  <img id="im" width="16px" src="images/edit-signiture.png"  />
  </a> 

  <a href="slide_up.php?id=<?php echo $f['id']; ?>" id="up" tip="Subir slide de posicao">
  <img id="im" width="16px" src="images/up.png"  />
  </a> 

  <a href="slide_down.php?id=<?php echo $f['id']; ?>" id="up" tip="Descer slide de posicao">
  <img id="im" width="16px" src="images/down.png"  />
  </a> 

</div>

<?php
}
?>


<?php require_once "footer.php"; ?>
